#include "XThreadPool.h"
#include "XThread.h"
#include<thread>
#include<iostream>
#include"XFtpServerCMD.h"
using namespace std;
void XThreadPool::dispatch(XFtpServerCMD* task) {
	if (!task)
		return;
	int tid = (lastThread + 1) % threadCount;
	lastThread = tid;
	XThread* t = threads[tid];
	t->addtask(task);
	t->Active();
}
void XThreadPool::Init(int threadCount) {
	this->threadCount=threadCount;
	this->lastThread = -1;
	for (int i = 0; i < threadCount; i++){
		XThread* t = new XThread();
		cout << "create thread " << i << endl;
		t->id = i + 1;
		t->start();
		threads.push_back(t);
		this_thread::sleep_for(10ms);
	}
}
